package cn.jn.lhm.cms.handler;

import cn.jn.lhm.cms.entity.CrmBanner;
import cn.jn.lhm.cms.service.CrmService;
import cn.jn.lhm.utils.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author LHM
 * @Tips 热爱每一天，奋斗每一天
 * @date 2020/6/9 - 19:12
 */
@RestController
@RequestMapping("/cms/admin")
public class BannerAdminHandler {

    @Resource
    private CrmService crmService;

    @GetMapping("/page/banner/{current}/{limit}")
    public R getBannerInfo(@PathVariable("current")Long current,
                           @PathVariable("limit")Long limit){
        Page<CrmBanner> bannerPage = new Page<>();
        return crmService.page(bannerPage);
    }


    @PostMapping("/addBanner")
    public R addBanner(@RequestBody CrmBanner crmBanner){
        crmService.save(crmBanner);
        return R.ok();
    }

    @PostMapping("/updateBanner")
    public R updateBannerInfo(@RequestBody CrmBanner crmBanner){
        crmService.updateBannerInfo(crmBanner);
        return R.ok();
    }

    @DeleteMapping("/deleteBanner/{id}")
    public R deleteBannerInfoById(@PathVariable("id")String id){
        crmService.deleteBannerInfo(id);
        return R.ok();
    }

}
